<?php

namespace app\api\controller;
use app\common\controller\Api;
use think\Db;

/**
 * 动态相关
 */
class Dongtai extends Api
{

    // 无需登录的接口,*表示全部
    protected $noNeedLogin = [''];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    /**
     * 发布动态
     */
    public function adddongtai(){
        $user=$this->auth->getUser();

        $desc=$this->request->param('desc');
        $images=$this->request->param('images');

        $user=Db::name('user')->where(['id'=>$user['id']])->find();


        Db::name('aa_dongtai')
            ->data(['desc'=>$desc,'images'=>$images,'user_id'=>$user['id'],'name'=>$user['name'],'avatar'=>$user['avatar'],'time'=>time()])
            ->insert();

        $this->success('操作成功');




    }


    /**
     * 所有的提交
     */

// ... existing code ...
public function getalldongtai(){
    // 获取当前页码，默认为第1页
    $page = $this->request->param('page', 1);
    // 每页显示的记录数
    $pageSize = 10;

    $list = Db::name('aa_dongtai')
        ->order('id desc')
        // 实现分页查询
        ->page($page, $pageSize)
        ->select();

    foreach ($list as &$key) {
        // 将时间戳格式化为指定日期时间格式
        $key['time'] = date('Y-m-d H:i', $key['time']);
        // 将图片字符串按逗号分割成数组
        $key['images'] = explode(',', $key['images']);
    }

    $this->success('操作成功', $list);
}
// ... existing code ...





}
